package com.yitao.cms.controller.expressage;

import com.skipper.base.bean.DataOutput;
import com.skipper.base.bean.PagedOutput;
import com.yitao.cms.config.aopLog.LogAnnotation;
import com.yitao.cms.service.expressage.ExpressageSubscribeLogCmsService;
import com.yitao.cms.service.expressage.Kuaidi100CmsService;
import com.yitao.cms.vo.expressage.ExpressageSubscribeLogVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 快递100相关
 *
 * @Date: 2019/6/11 19:59
 * @Author: Kien
 */
@Api(value = "cms/kuaidi100", description = "快递100物流信息", tags = {"cms-order-logistics"})
@RestController
@RequestMapping(value = "/cms/logistics" , produces = {"application/json"})
public class Kuaidi100Controller {
    @Autowired
    private Kuaidi100CmsService kuaidi100Service;
    @Autowired
    private ExpressageSubscribeLogCmsService expressageSubscribeLogCmsService;

    @ApiOperation("快递100消息订阅")
    @LogAnnotation(targetType = "subscribe", remark = "快递100消息订阅")
    @RequestMapping(value = "/subscribe", method = RequestMethod.POST)
    public DataOutput subscribeData(@ApiParam(value = "快递公司编码", required = true) @RequestParam(value = "company")String company,
                                    @ApiParam(value = "快递单号", required = true) @RequestParam(value = "number") String number,
                                    @ApiParam(value = "手机号") @RequestParam(value = "phone", required = false) String phone){
        return kuaidi100Service.subscribeData(company, number, phone);
    }

    @ApiOperation("获取物流订阅记录列表")
    @RequestMapping(value = "/findExpressage", method = RequestMethod.POST)
    public PagedOutput<ExpressageSubscribeLogVo> getExpressageSubscriberLogList(@ApiParam(value = "物流公司名称") @RequestParam(value = "companyName", required = false) String companyName,
                                                                                @ApiParam(value = "物流单号") @RequestParam(value = "deliveryNo", required = false) String deliveryNo,
                                                                                @ApiParam(value = "开始时间") @RequestParam(value = "staDate", required = false) String staDate,
                                                                                @ApiParam(value = "结束时间") @RequestParam(value = "endDate", required = false) String endDate,
                                                                                @ApiParam(value = "分页参数，表示当前页", required = true, defaultValue = "1") @RequestParam(value = "pageNo") Integer pageNo,
                                                                                @ApiParam(value = "分页参数，表示每页显示多少条记录", required = true, defaultValue = "10") @RequestParam(value = "pageSize") Integer pageSize){
        if(StringUtils.isEmpty(companyName)) {
            companyName = null;
        }
        if(StringUtils.isEmpty(deliveryNo)) {
            deliveryNo = null;
        }
        return expressageSubscribeLogCmsService.getExpressageSubscribeLogList(companyName, deliveryNo, staDate, endDate, pageNo, pageSize);
    }

    @ApiOperation("快递单号再次订阅")
    @LogAnnotation(targetType = "againSubscribe", remark = "快递单号再次订阅")
    @RequestMapping(value = "/againSubscribe", method = RequestMethod.POST)
    public DataOutput againSubscribe(@ApiParam(value = "id") @RequestParam(value = "id") Long id,
                                     HttpServletRequest request){
        return kuaidi100Service.againSubscribe(id, request);
    }



}
